<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="dashboard.User" %>

	<p>	<u><b>Top 10</b></u>
		
		<% 
			String sort0 = "";
			HashMap<String, Double> allBoard0 = new HashMap<String, Double>();
			int ownPosition0 = 0;
			double ownValue0 = 0;
			User currentUser0 = new User();
			HashMap<String, Double> favouritesBoard0 = new HashMap<String, Double>();
			List<String> favourites0 = new ArrayList<String>();
			try{
			sort0 = (String) session.getAttribute("sort");
			allBoard0 = (HashMap<String, Double>) session.getAttribute("allBoard");
			ownPosition0 = (Integer) session.getAttribute("ownPosition");
			ownValue0 = (Double) session.getAttribute("ownValue");
			currentUser0 = (User) session.getAttribute("user");
			favouritesBoard0 = (HashMap<String, Double>) session.getAttribute("favouritesBoard");
			favourites0 = (List<String>) session.getAttribute("favourites");
			}
			finally
			{
				
			}
		if (!allBoard0.isEmpty()){ %>
	<table class='tablesorter' id='LinkTable' width='97%'>
	<thead>
		<tr>
			<th colspan="1" width="10%">Number 
			<th colspan='1'width="30%">Name</th>
			<th colspan='1'width="40"><%=sort0%></th>
			<th colspan='1'width="20%">Favorite</th>
		</tr>
	</thead>
		<tbody>
	<%
	Iterator it = allBoard0.entrySet().iterator();
	double number = 1;
	while (it.hasNext()) {
   	 Map.Entry pairs = (Map.Entry)it.next();
	double totalCount  = (Double) pairs.getValue();
	 totalCount = totalCount * 100;
	 totalCount = Math.round(totalCount);
	 totalCount = totalCount / 100;
	 String userName = (String) pairs.getKey();	
	
		
%>
<tr>
<td>
	<%=Math.round(number)%>
</td>
<td>
	<%=userName%>
</td>


<td>
	<%=totalCount%>	
</td>
<td>
	<a href="Favourites?action=addfav&userName=<%=userName%>">add as favorite</a>	
</td>
</tr>

	<%
	number++;
}
%>
	
	</tbody></table>
	<font size="2"><i>Total students : <%=session.getAttribute("size")%></i></font><br>
	
	
	<%} else{ %><br>
	 There are currently no <%=sort0%>.
	
	<%} %>
	</p>
	<p>
		<u><b>You</b></u><br>
	<% if(ownPosition0!=-1){ %>
	<table class='tablesorter' id='LinkTable' width='97%'>
	<thead>
		<tr>
		<th colspan="1" width="10%">Number 
			<th colspan='1'width="30%">Name</th>
			<th colspan='1'width="40"><%=sort0%></th>
			<th colspan='1'width="20%">View your stats</th>
		</tr>
	</thead>
	<tbody>
	<%
	ownValue0 = ownValue0 * 100;
	ownValue0 = Math.round(ownValue0);
	ownValue0 = ownValue0 / 100;
	
	%>	<tr><td colspan='1'><%=ownPosition0 %></td>
	<td colspan='1'><%=currentUser0.getUserName()%></td>
	<td colspan='1'><%=ownValue0%></td>
	<td colspan='1'><a href="statistics.jsp?ref=leaderboard">Stats</a></td></tr>
	</tbody></table>
	<%
	} else{%>
	You don't have any <%=sort0%>.	
<%} %>
</p>
<p>
	<b><u>Your Favorites</b></u><br>
	<table class='tablesorter' id='LinkTable' width='97%'>
	<thead>
		<tr>
		<th colspan="1" width="10%">Number 
			<th colspan='1'width="30%">Name</th>
			<th colspan='1'width="40"><%=sort0%></th>
			<th colspan='1'width="20%">Favorite</th>
		</tr>
	</thead>
		<tbody>
	<%
	Iterator it2 = favouritesBoard0.entrySet().iterator();
	int i = 0;
	while (it2.hasNext()) {
   	Map.Entry pairs = (Map.Entry)it2.next();
	double totalCount  = (Double) pairs.getValue();
	totalCount = totalCount * 100;
	totalCount = Math.round(totalCount);
	totalCount = totalCount / 100;
	int userPosition= (Integer) pairs.getKey();	
	String userName=favourites0.get(i);
	i++;
		
%>
<tr>
<td>
	<%=Math.round(userPosition)%>
</td>
<td>
	<%=userName%>
</td>
<td>
	<%=totalCount%>	
</td>
<td>
	<a href="Favourites?action=removefav&userName=<%=userName%>"><img src="../img/cross.png"></a> | 
	<a href="Favorites.jsp?action=view">User info</a>
	
</td>
</tr>

	<%
}
%>
	
	</tbody></table>
	<% if(favourites0.isEmpty()){
		
		%>
		<i>You don't have any favorites yet. Click <a href="Favorites.jsp">here</a> to add some!</i>
		<%
	}
	%></p>